home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / lcppb.zip / LCPP04.ZIP / ARRAYPTR.CPP < prev    next >
C/C++ Source or Header  |  1991-07-03  |  813b  |  33 lines

  1. // arrayptr.cpp -- Show relationship between arrays and pointers
  2.  
  3. //#include <stream.hpp>
  4. #include <iostream.h>
  5.  
  6. #define MAX 10       // Size of array
  7.  
  8. void showFirst(void);
  9.  
  10. int array[MAX];      // Global array of MAX integers
  11.  
  12. main()
  13. {
  14.   array[0] = 123;   // Assign value using indexing
  15.   showFirst();      // Display value both ways
  16.   *array = 321;     // Assign value using pointer
  17.   showFirst();      // Display value both ways
  18. }
  19.  
  20. void showFirst(void)
  21. {
  22.   cout << "array[0] = " << array[0] << '\n';  // Via index
  23.   cout << "*array   = " << *array   << '\n';  // Via pointer
  24. }
  25.  
  26.  
  27. // Copyright (c) 1990 by Tom Swan. All rights reserved
  28. // Revision 1.00    Date: 08/31/1990   Time: 05:06 pm
  29.  
  30. // Revision 1.01    Date: 07/03/1991   Time: 04:00 pm
  31. // Converted for Borland C++ 2.0
  32.  
  33.